﻿IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cms_sp_MediaContentSelectOne]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [dbo].[cms_sp_MediaContentSelectOne]
GO
 CREATE PROCEDURE [dbo].[cms_sp_MediaContentSelectOne] 
 ( 
 	@Id int 
 ) 
 AS	 
 begin 
 	select mc.*,
		   mc.[MediaContentId] as [Id],
		   l.MediaFileId as MainFile_Id
	from MediaContents mc
	left join (select * from MediaContentFileLinks where IsPrimary=1) l on l.MediaContentId = mc.MediaContentId
 	where mc.MediaContentId = @Id 
 end 

GO